<template>
	<view class="content">
		<view class="userInfo" @tap="getUserProfile">
			<view class="userInfocentent">
				<view class="userPriture">
					<image :src=" userInfo.avatarUrl || '../../static/img/icon_1.png'" mode=""></image>
				</view>
				<view class="userTxt">
					<view class="name f22">{{userInfo.nickName || '点击登录'}}</view>
					<view class="userId f20">{{userInfo.wxUserNo?'ID:  '+userInfo.wxUserNo:'获取更多功能'}}</view>
				</view>
			</view>
		</view>
		<view class="mineMiddle">
			<view class="formItem f16" @click="jump('warranty')" v-if="userInfo.wxUserLevel===0">
				<icon class="iconfont iconbaoxiuka lefticon" type="" />
				<view class="text">保修卡</view>
				<view class="msg" v-show="s_data!=0">{{s_data}}</view>
				<view class="right">
					<icon class="iconfont iconarrow-right" type="" />
				</view>
			</view>
			<view class="formItem f16" @click="jump('placeInfo')" v-if="userInfo.wxUserLevel===0">
				<icon class="iconfont iconweizhi1 lefticon" type="" />
				<view class="text">位置信息</view>
				<view class="msg" v-show="false">1</view>
				<view class="right">
					<icon class="iconfont iconarrow-right" type="" />
				</view>
			</view>
			<view class="formItem f16" @click="jump('serverList')" v-if="userInfo.wxUserLevel===0">
				<icon class="iconfont iconfuwujilu lefticon" type="" />
				<view class="text">服务记录</view>
				<view class="msg" v-show="false">1</view>
				<view class="right">
					<icon class="iconfont iconarrow-right" type="" />
				</view>
			</view>
			<view class="formItem f16" @click="jump('warranty_s')" v-if="userInfo.wxUserLevel===1">
				<icon class="iconfont iconbaoxiuka lefticon" type="" />
				<view class="text">保修卡_s</view>
				<view class="msg" v-show="s_data!=0">{{s_data}}</view>
				<view class="right">
					<icon class="iconfont iconarrow-right" type="" />
				</view>
			</view>
			<view class="formItem f16" @click="jump('serverList_s')" v-if="userInfo.wxUserLevel===1">
				<icon class="iconfont iconfuwujilu lefticon" type="" />
				<view class="text">服务记录_s</view>
				<view class="msg" v-show="false">1</view>
				<view class="right">
					<icon class="iconfont iconarrow-right" type="" />
				</view>
			</view>
		</view>
		<view class="mineMiddle mineBottom" @tap="fallow">
			<view class="formItem f16">
				<icon class="iconfont iconshoucang lefticon" type="" />
				<view class="text">关注公众号</view>
				<view class="msg" v-show="false">1</view>
				<view class="right">
					<icon class="iconfont iconarrow-right" type="" />
				</view>
			</view>
			<view class="formItem f16" @tap="showH5">
				<image src="../../static/img/logo3.png" class="img lefticon"></image>
				<view class="text">访问官网</view>
				<view class="msg" v-show="false">1</view>
				<view class="right">
					<icon class="iconfont iconarrow-right" type="" />
				</view>
			</view>
			<view class="formItem f16" @tap="open">
				<icon class="iconfont icondianhua lefticon" type="" />
				<view class="text">联系我们</view>
				<view class="msg" v-show="false">1</view>
				<view class="right">
					<icon class="iconfont iconarrow-right" type="" />
				</view>
			</view>
			<view class="formItem f16" @tap="logout" v-if="userInfo">
				<icon class="iconfont icontuichu lefticon" type="" />
				<view class="text">退出</view>
				<view class="msg" v-show="false">1</view>
				<view class="right">
					<icon class="iconfont iconarrow-right" type="" />
				</view>
			</view>
		</view>
		<uni-popup ref="popup" type="bottom">
			<view class="popupBox">
				<view class="phonenumber" @click="callPhone">
					<icon class="iconfont icon-telephone f22" type=""></icon>
					<text class="number f16">
						<text class="head">188</text>
						77 183 183
					</text>
				</view>
				<view class="phonenumber" @click="callPhone">
					<icon class="iconfont icon-telephone f22" type=""></icon>
					<text class="number f16">
						<text class="head">188</text>
						77 183 183
					</text>
				</view>
				<view class="cancel f18" @click="close">
					取消
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				userInfo: "",
				islogin:false,
				s_data:0,
				hideLogout:true
			}
		},
		onLoad() {
			this._isLogin();
		},
		onShow(){
			
		},
		methods: {
			showH5(){
				wx.navigateTo({url:"./webView"})
				// wx.miniProgram.postMessage({ data: 'foo' })
				// wx.miniProgram.postMessage({ data: {foo: 'bar'} })
				// wx.miniProgram.getEnv(function(res) { console.log(res.miniprogram) })
			},
			logout(){
				// this.postApi('logout','GET',{loading:false}).then(res=>{
				// 	console.log('resssslogout',res)
					
				// })
				uni.removeStorageSync('User_token')
				uni.removeStorageSync('User_tokenTime')
				uni.removeStorageSync('User_info')
				this.userInfo=null;
				this.islogin=false;
				this.hideLogout=true
				uni.showToast({
					title:'退出登录成功'
				})
			},
			fallow(){
				
			},
			open() {
				// 通过组件定义的ref调用uni-popup方法
				this.$refs.popup.open()
			},
			close() {
				this.$refs.popup.close()
			},
			callPhone() {
				uni.makePhoneCall({
					phoneNumber: '18877183183' //仅为示例
				});
			},
			jump(str) {
				if (str === "warranty") {
					uni.navigateTo({
						url: "../luckLock/warrantyCard/warrantyPage/warrantyPage"
					})
				} else if (str === "placeInfo") {
					uni.navigateTo({
						url: "../luckLock/placeInfo/placeInfo?s=0&svcId=1"
					})
				} else if (str === "serverList") {
					uni.navigateTo({
						url: "../luckLock/serverList/serverPage"
					})
				}
				if (str === "warranty_s") {
					uni.navigateTo({
						url: "../luckLock/placeInfo/placeInfo?s=1"
					})
				} else if (str === "serverList_s") {
					uni.navigateTo({
						url: "../luckLock/serverList/serverPage_s"
					})
				}
			},
			//是否登录
			_isLogin() {
				var that = this;
				wx.checkSession({
				　　　　success: (res)=>{
				　　　　　　console.log("处于登录状态");
							let token = uni.getStorageSync('User_token');
							let tokenTime = uni.getStorageSync('User_tokenTime');
							let nowDate =new Date().getTime();
							if(token){
								let tT = new Date(tokenTime).getTime()
								if(nowDate >= tT){
									console.log('token过期')
									this.upToken()
								}
								this.userInfo = uni.getStorageSync('User_info')
								this.islogin = true
								this.userInfo.wxUserLevel==1?this.getlistCount():this.getUser_listCount();
							}else{
								// this.getUserProfile(false,(userInfo)=>{
								// 	 this.userInfo = userInfo
								// 	 this.userInfo.wxUserLevel==1?this.getlistCount():this.getUser_listCount();
								// 	 this.islogin = true
								// })
							}
				　　　　},
				　　　　fail: (res)=>{
				　　　　　　console.log("需要重新登录");
				　　　　}
				
				　　})
			},
			getUser_listCount(){//用户保修卡
				this.postApi('listCountOnMini','POST',{data:{status:3,isReview:0}}).then(res=>{
					this.s_data = res.data
				})
			},
			getlistCount(){//锁匠待办
				this.postApi('s_listCount','GET',{}).then(res=>{
					console.log('res_s',res)
					this.s_data = res.data
					console.log(this.s_data)
				})
			}
			
		}
	}
</script>

<style lang="less" scoped>
	@import '@/common/common.less';

	.content {
		display: flex;
		flex-direction: column;
		height: 100%;

		.userInfo {
			background-color: @primary-color;
			height: 375rpx;
			padding-top: 92rpx;
			padding-bottom: 92rpx;
			margin-bottom: 17rpx;

			.userInfocentent {
				margin-left: 57rpx;
				display: flex;
				flex-direction: row;

				.userPriture {
					width: 118rpx;
					height: 118rpx;

					image {
						width: 100%;
						height: 100%;
						border-radius: 30rpx;
					}
				}

				.userTxt {
					margin-left: 55rpx;

					.name {
						font-weight: bold;
						color: #FFFFFF;
						// margin-top: -5rpx;
						margin-bottom: 13rpx;
					}

					.userId {
						color: #FFFFFF;
						// max-width: 50%;
					}
				}
			}
		}

		.mineMiddle {
			background-color: #FFFFFF;

			.formItem {
				border-bottom: 1rpx solid #e1e1e1;
				display: flex;
				flex-direction: row;
				padding-left: 39rpx;
				height: 101rpx;
				align-items: center;
				position: relative;

				.iconfont {
					margin-top: -2rpx;
				}

				.lefticon {
					margin-right: 28rpx;
					color: @primary-color;
				}

				.text {
					color: #555555;
					margin-right: 21rpx;
				}

				.msg {
					width: 46rpx;
					height: 46rpx;
					border-radius: 50%;
					background-color: #FF0000;
					color: #FFFDEF;
					text-align: center;
					line-height: 46rpx;
				}

				.right {
					position: absolute;
					right: 32rpx;
				}

				.img {
					width: 34rpx;
					height: 34rpx;
				}
			}
		}

		.mineBottom {
			margin-top: 18rpx;
			margin-bottom: 23rpx;
		}
		.popupBox {
			height: 180px;
			background-color: #FFFFFF;
			border-top-left-radius: 10px;
			border-top-right-radius: 10px;
		
			.phonenumber {
				height: 50px;
				line-height: 50px;
				text-align: center;
				border-bottom: 1px solid #CCCCCC;
		
				.iconfont {
					color: @primary-color;
					margin-right: 20px;
				}
		
				.number {
					.head {
						color: @primary-color;
					}
				}
			}
		
			.cancel {
				text-align: center;
				height: 50px;
				line-height: 50px;
			}
		}
	}
</style>
